const express=require('express')
const router= express.Router();
const db=require('../../utils/db')

// 查询收银流水
router.get('/getcashierwater',function(req,res){
    let mysql=`SELECT cash_rank,order_num,table_position,table_num,pay_way,cash_money,dis_money,user_name,order_time,customer_name,order_payfor_num FROM cash_flowing 
               JOIN order_information ON order_information.order_id=cash_flowing.cash_num
               JOIN table_area ON cash_flowing.cash_table_area=table_area.table_id
               JOIN discounts_management ON cash_flowing.cash_dis_limit=discounts_management.dis_id
               JOIN pay_method ON order_information.order_pay_way=pay_method.pay_id
               JOIN customer ON order_information.order_username=customer.customer_id
               JOIN USER ON order_information.order_user_id=user.user_id GROUP BY order_num`
    db(mysql,null,function(err,data){
        if(err){
            return res.json({
                code: 500,
                msg: '查询收银流水失败，请稍后重试'
            })
        }
        res.json({
            code: 200,
            msg: '查询收银流水成功',
            data: data
        })
    })
})

// 模糊查询订单
router.get('/getorderid',function(req,res){
    let mysql=`SELECT cash_rank,order_num,table_position,table_num,pay_way,cash_money,dis_money,user_name,order_time,customer_name,order_payfor_num FROM cash_flowing 
               JOIN order_information ON order_information.order_id=cash_flowing.cash_num
               JOIN table_area ON cash_flowing.cash_table_area=table_area.table_id
               JOIN discounts_management ON cash_flowing.cash_dis_limit=discounts_management.dis_id
               JOIN pay_method ON order_information.order_pay_way=pay_method.pay_id
               JOIN customer ON order_information.order_username=customer.customer_id
               JOIN USER ON order_information.order_user_id=user.user_id
               WHERE order_id LIKE ? AND order_time BETWEEN ? AND ? AND pay_way=? AND table_position=? GROUP BY order_num`
    db(mysql,['%'+req.query.orderId+'%',req.query.time[0],req.query.time[1],req.query.payWay,req.query.tableArea],function(err,data){
        if(err){
            return res.json({
                code: 500,
                msg: '模糊查询订单失败，请稍后重试'
            })
        }
        res.json({
            code: 200,
            msg: '模糊查询订单成功',
            data: data
        })
    })
})




module.exports = router